﻿@using OA.Models;
@model Post

@{
    var options = new AjaxOptions
    {
        OnBegin = "openLoading",
        OnSuccess = "ajaxSuccess"
    };
}

@using (Ajax.BeginForm("Update", "Post", options, new { @class = "w-form" }))
{
    @Html.HiddenFor(d => d.Id)
    <div class="w-content">
        <div class="form-table">
            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.Name)
                </div>
                <div class="form-td">
                    @Html.Kendo().TextBoxFor(d => d.Name)
                    <div>@Html.ValidationMessageFor(d => d.Name)</div>
                </div>
            </div>
            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.Sort)
                </div>
                <div class="form-td">
                    @Html.Kendo().TextBoxFor(d => d.Sort)
                </div>
            </div>

            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.Grade)
                </div>
                <div class="form-td">
                    @Html.Kendo().TextBoxFor(d => d.Grade)
                </div>
            </div>

            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.Remarks)
                </div>
                <div class="form-td">
                    @Html.Kendo().TextBoxFor(d => d.Remarks)
                </div>
            </div>
        </div>
    </div>
    <div class="w-footer">
        @(
            Html.Kendo().Button()
            .Name("Cancel")
            .Events(e => e.Click("closeWindow"))
            .HtmlAttributes(new { type = "button" })
            .Icon("cancel")
            .Content("取消")
        )
        @(
            Html.Kendo().Button()
            .Name("Enter")
            .Icon("check")
            .Content("更新")
            .HtmlAttributes(new { @class = "k-primary" })
        )
    </div>
}

<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

<script>
    function ajaxSuccess(response) {
        if (response.IsSuccess) {
            $("#grid").data("kendoGrid").dataSource.read();
            closeWindow();
            openNotification(response.Message, "success");
        }
        else {
            openNotification(response.Message, "error");
        }
        closeLoading();
    }
</script>